var ajaxUrl = require('../../../utils/url.js');
var encrypt = require('../../../utils/encrypt.js');
const app = getApp()
Page({
  data: {
		upUser: [],
    downUser: []
	},
	onLoad(){
		this.fetchData()
	},
	fetchData () {
		const self = this
		let params = {
			token: app.globalData.token
		}
		wx.request({
      method: "POST",
      url: ajaxUrl.relationship(),
      data: params,
      success: function(res){
        if(res.data.code === 200){
          self.setData({
						upUser: res.data.data.upUser,
						downUser: res.data.data.downUser,
          })
        }else{
          console.error(res.data.msg)
        }
      }
    })
	},
	unbind (e) {
		const self = this
		let upUserId = e.currentTarget.dataset.id
		let params = {
			action: 1,
			toId: upUserId
		}
		params = encrypt.encrypt(params)
		wx.showModal({
      content: "确定解除你们之间的关系吗?你们之间将失去优惠的权利哦",
      confirmText: "确定",
			cancelText: "取消",
			success: function(res) {
				if (res.confirm) {
					wx.request({
						method: "POST",
						url: ajaxUrl.addMessage(),
						data: params,
						success: function(res){
							if(res.data.code === 200){
								self.showToast({title:'操作成功'})
							}else{
								console.error(res.data.msg)
							}
						}
					})
				} else if (res.cancel) {
					console.log('用户点击取消')
				}
			}
    })
	}
})